﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VideoRentalShop.Controller;
using VideoRentalShop.Model;

namespace VideoRentalShop.View.Windows.OrderList
{
    /// <summary>
    /// Logika interakcji dla klasy AdditionalPanel.xaml
    /// </summary>
    public partial class AdditionalPanel : UserControl
    {
        public AdditionalPanel()
        {
            InitializeComponent();
            CreateColumns();
        }


        private void CreateColumns()
        {
            lstGridDetails.Columns.Add(new GridViewColumn { Header = "Tytuł", DisplayMemberBinding = new Binding("Title") });
            lstGridDetails.Columns.Add(new GridViewColumn { Header = "Wymagana data oddania", DisplayMemberBinding = new Binding { Path = new PropertyPath("MaxReturnDate"), StringFormat = "{0:dd.MM.yyyy HH:mm}" } });
            lstGridDetails.Columns.Add(new GridViewColumn { Header = "Data oddania", DisplayMemberBinding = new Binding { Path = new PropertyPath("ReturnDate"), StringFormat = "{0:dd.MM.yyyy HH:mm}" } });
        }


        public void LoadItem(Order item)
        {
            if (item == null)
            {
                Clear();
            }
            else
            {
                var result = new List<dynamic>();
                var items = item.OrderDetails;

                foreach (var detail in items)
                {
                    result.Add(new
                    {
                        Title = detail.Movie.Title,
                        MaxReturnDate = detail.MaxReturnDate,
                        ReturnDate = detail.ReturnDate
                    });
                }

                lstDetails.ItemsSource = result;
            }
        }

        public void Clear()
        {
            lstDetails.ItemsSource = null;
        }
    }
}
